package net.lab1024.sa.admin.module.business.erp.poo.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.erp.poo.dao.SubordaDao;
import net.lab1024.sa.admin.module.business.erp.poo.domain.entity.SubordaEntity;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.SubordaAddForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.SubordaQueryForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.SubordaUpdateForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.vo.SubordaVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 暂收送检单行 Service
 *
 * @Author AKITA
 * @Date 2025-07-24 14:41:33
 * @Copyright AKITA
 */

@Service
public class SubordaService {

    @Resource
    private SubordaDao subordaDao;

    /**
     * 分页查询
     */
    public PageResult<SubordaVO> queryPage(SubordaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<SubordaVO> list = subordaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(SubordaAddForm addForm) {
        SubordaEntity subordaEntity = SmartBeanUtil.copy(addForm, SubordaEntity.class);
        subordaDao.insert(subordaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(SubordaUpdateForm updateForm) {
        SubordaEntity subordaEntity = SmartBeanUtil.copy(updateForm, SubordaEntity.class);
        subordaDao.updateById(subordaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        subordaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        subordaDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
